//
// Created by mabinjie on 2024/10/29.
//

#ifndef REGISTER_RESPONSE_HPP
#define REGISTER_RESPONSE_HPP
#include <cstdint>

#include "common/types.h"
#include "protocol/message/jtt808_body.hpp"

namespace protocol::platform {

enum class RegisterResult {
    SUCCESS = 0,
    CAR_ALREADY_REGISTERED = 1,
    CAR_NOT_IN_DATABASE = 2,
    TERMINAL_ALREADY_REGISTERED = 3,
    TERMINAL_NOT_IN_DATABASE = 4
};

class RegisterResponse final : public jtt808_body {
public:
    uint16_t register_message_sn_;
    uint8_t result_;
    common::container_t<char> auth_code_;

    IMPLEMENT_SIZEABLE(register_message_sn_, result_, auth_code_)
    IMPLEMENT_TOSTRING(message_id_, register_message_sn_, result_, auth_code_)

    RegisterResponse() : jtt808_body(0x8100) {}
    RegisterResponse(const uint16_t register_message_id, RegisterResult result, const common::Container<char>& auth_code)
        : jtt808_body(0x8100), register_message_sn_(register_message_id), result_(static_cast<uint8_t>(result)) {
        auth_code_ = std::make_shared<common::Container<char>>(auth_code);
    }

    RegisterResponse(const RegisterResponse &other) = default;

    RegisterResponse(RegisterResponse &&other) noexcept = default;

    RegisterResponse & operator=(const RegisterResponse &other) = default;

    RegisterResponse & operator=(RegisterResponse &&other) noexcept = default;

    ~RegisterResponse() override = default;

    void serialize(common::MessagePackWriter &writer) override {
        writer.writeUint(register_message_sn_);
        writer.writeByte(result_);
        auth_code_->serialize(writer);
    }

    void deserialize(common::MessagePackReader &reader) override {
        reader.readUint(register_message_sn_);
        reader.readByte(result_);
        auth_code_ = std::make_shared<common::Container<char>>();
        auth_code_->deserialize(reader);
    }
};

}

#endif //REGISTER_RESPONSE_HPP
